package com.valenx.distributedmulticamerasystem.utils;

import com.valenx.distributedmulticamerasystem.ResourceTable;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;

//吐司弹框工具
public class ToastUtil {
    public static void showToast(Context context, String string) {
        DirectionalLayout directionalLayout = (DirectionalLayout) LayoutScatter.getInstance(context).parse(ResourceTable.Layout_toast, null, false);
        Text text = directionalLayout.findComponentById(ResourceTable.Id_toast_text);
        text.setText(string);

        ToastDialog toastDialog = new ToastDialog(context);
        toastDialog.setAlignment(LayoutAlignment.BOTTOM);
        toastDialog.setContentCustomComponent(directionalLayout);
        toastDialog.setOffset(0,420);
        toastDialog.setTransparent(true);
        toastDialog.show();
    }
}
